﻿using System;
using System.Collections.Generic;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Zj.HttpCodeDemo.Domain.Entities;

namespace Zj.HttpCodeDemo.Repository.Models.Mappings
{
    /// <summary>
    /// Conceptual model category fluent api config.
    /// </summary>
    public class CategoryMap
         : EntityTypeConfiguration<Category>
    {
        public CategoryMap()
        {
            //table
            this.ToTable("Category", "dbo");

            //keys
            HasKey(t => t.Id);

            //properties
            this.Property(t => t.Id)
                .HasColumnName("Id")
                .IsRequired();
            this.Property(t => t.Name)
                .HasColumnName("Name")
                .HasMaxLength(16)
                .IsUnicode(true)
                .IsRequired();

            //relations
            this.HasMany(t => t.Newss)
                .WithRequired(t => t.Category)
                .HasForeignKey(t => t.CategoryId);
        }
    }
}
